//
//  RegistOneViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/1/26.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "RegistOneViewController.h"
#import "RegistTwoViewController.h"

@interface RegistOneViewController ()
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroView;
@property (strong, nonatomic) IBOutlet UITextField *phoneField;
@property (strong, nonatomic) IBOutlet UIButton *commitButton;

@end

@implementation RegistOneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
    // Do any additional setup after loading the view.
}

- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];
    
    self.commitButton.layer.cornerRadius = 20*VerticalRatio();
    [_phoneField setValue:[UIColor colorWithWhite:0.498 alpha:1.000]
                      forKeyPath:@"_placeholderLabel.textColor"];
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 505), NO);

}

- (IBAction)back:(id)sender {
    MyNavigationViewController * navC = (MyNavigationViewController *)self.navigationController;
    [navC popViewController];
}

#pragma mark === 提交
- (IBAction)commitHandel:(id)sender {
    [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
    if ([Common dataIsNULL:_phoneField.text]) {
        [CWHUDTips showTips:@"请输入手机号码"];
        return;
    }
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:_phoneField.text forKey:@"phone"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:SX_GetRegistNumber withHttpType:@"POST" withTag:SX_QueryVerificationCodeDataTag];
 
}


#pragma mark  === 用户协议
- (IBAction)userDeal:(id)sender {
    UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
    UIViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"UserProtocal"];
    MyNavigationViewController * navC = (MyNavigationViewController *)self.navigationController;
    [navC pushToViewController:page ];
}

#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    if (tag==SX_QueryVerificationCodeDataTag) {
        
        if (  [[database valueForKey:@"type"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:2];
            
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
            RegistTwoViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"RegistTwo"];
            page.phoneNumber = _phoneField.text;
            page.pageFinishBlock = ^(NSString *str){
                if (self.pageFinishBlock) {
                    self.pageFinishBlock(@"");
                }
                MyNavigationViewController * navC = (MyNavigationViewController *)self.navigationController;
                [navC popViewController];
            };

            MyNavigationViewController * navC = (MyNavigationViewController *)self.navigationController;
            [navC pushToViewController:page ];

        }
        
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
    
    //
    [self dismissWaitDialog];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
